<?php
/**
 * Created by PhpStorm.
 * User: gakuin
 * Date: 16/8/18
 * Time: 下午1:32
 */
namespace app\models;

use yii\db\ActiveRecord;

class Collection extends ActiveRecord{
    public  function  getCollections(){

        $id = \Yii::$app->user->id;
        $collections = Collection::find()->where(['user_id' => $id,'del_flag'=>'1',])->orderBy('create_time DESC')->asArray()->all();
        return $collections;
    }

    public function getOneCollection($user_id,$commodity_id){

        $collections = Collection::find()->where(['user_id' => $user_id,'del_flag'=>'1','commodity_id' =>$commodity_id,])->asArray()->one();
        return $collections;
    }

    public function getCollectionId($commodity_id){
        $collection_id = Collection::find()->where(['commodity_id'=>$commodity_id])->select('collection_id')->orderBy('collection_id DESC')->scalar();
        return $collection_id;
    }

    public function getCollectionCommodityIds(){
        $id = \Yii::$app->user->id;
        $commodity_ids = Collection::find()->select('commodity_id')->where(['user_id' => $id,'del_flag'=>'1',])->orderBy('create_time DESC')->asArray()->all();
        return $commodity_ids;
    }

    public function getCollectionDeleteFlag($commodity_id){
        $id = \Yii::$app->user->id;
        $collection_flag = Collection::find()->where(['commodity_id'=>$commodity_id,'user_id'=>$id])->select('del_flag')->orderBy('create_time DESC')->scalar();
        return $collection_flag;
    }

}